﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using ClassLibrary.Entity;
using System.Data;

namespace ClassLibrary.DAO
{
    public class TblContentCommentDAO
    {
         private DBService _db = null;
         public TblContentCommentDAO(string ConnectionString)
         {
            _db = new DBService(ConnectionString);
         }

         public bool Insert(TblComment comment)
         {
             bool flag = false;
             try
             {
                 int result = 0;
                 result = _db.ExeSP_NonQuery("sp_CommentIns",
                     new string[] { "@ItemID", "@DateComment", "@ContentComment", "@AccountID" },
                     new object[] { comment.ItemID, comment.DateComment, comment.ContentComment, comment.AccountID },
                     CommandType.StoredProcedure);
             }
             catch (Exception ex)
             {
                 throw ex;
             }
             return flag;
         }

         public DataTable GetComment(int ItemID)
         {
             DataTable dt = null;
             try
             {
                 dt = _db.ExeSP_DataTable("select TblUserAccount.*, TblComment.ContentComment, TblComment.DateComment, TblComment.ItemID from TblComment inner join TblUserAccount on TblComment.AccountID=TblUserAccount.AccountID where ItemID = @ItemID Order By DateComment DESC",
                    new string [] {"@ItemID"},
                    new object [] {ItemID },
                     CommandType.Text);
             }
             catch (Exception ex)
             {
                 throw ex;
             }
             return dt;
         }
    }
}
